in 𝕏 M P
Home /Slashing VRAM Usage: Practical Quantization Techniques for Deploying Local LLMs

Slashing VRAM Usage: Practical Quantization Techniques for Deploying Local LLMs

Running large language models (LLMs) on consumer hardware almost always hits the exact same wall: VRAM limitations. A standard 70-billion-parameter model stored in 16-bit floating-point precision ($\text{FP16}$) requires roughly 70B × 2 bytes = 140 GB of VRAM just to load its weights into memory—completely out of reach for consumer GPUs like an RTX 4090 (24 GB) or even a dual-GPU workstation.


Quantisation is the primary technique that bridges this gap. By reducing the numerical precision of a model's weights and activations, you can shrink VRAM footprints by 50% to 75% with negligible impact on output quality.

Here is a practical, engineering-focused breakdown of how q works, the dominant formats in use, and how to pick the right strategy for local deployment.

1. What Actually Happens During Quantisation?

At its core, quantisation maps high-precision continuous values (like 16-bit floats) to lower-precision discrete integer values (like 8-bit or 4-bit integers).

$$\text{FP16} \x right arrow{\text{Quantization}} \text{INT8} \text{ / } \text{INT4}$$

When a model runs in $\text{FP16}$, every parameter consumes 2 bytes (16 bits) of VRAM. A 7-billion parameter model requires:

$$\text{7B parameters} \times 2 \text{ bytes} = 14 \text{ GB VRAM (for weights alone)}$$

Add the Key-Value (KV) cache for long contexts and activation overhead, and you need an 18–24 GB GPU just to run inference comfortably.

Mathematical Mapping

Linear quantization scales floating-point numbers ($x$) into an integer range using a Scale Factor ($S$) and a Zero-Point ($Z$):

$$q = \text{round}\left(\frac{x}{S}\right) + Z$$

To retrieve the approximate original value during matrix multiplication:

$$\hat{x} = S \times (q - Z)$$

Because integer operations ($\text{INT8}/\text{INT4}$) process much faster on modern Tensor Cores and require significantly less memory bandwidth, quantisation reduces both memory consumption and decoding latency.

2. PTQ vs. QAT: Two Distinct Approaches

There are two primary ways to quantise a model:

For consumer deployment, Post-Training Quantisation (PTQ) is the standard choice. You take an existing open-weights model (e.g., Llama, Mistral, Qwen) and convert it directly on local hardware or via community tools without retraining from scratch.

3. The Major Quantisation Formats Compared

Different deployment runtimes rely on different quantisation formats. Choosing the wrong format for your target backend will result in poor GPU utilisation or failed execution.

FormatNative RuntimeTarget HardwarePrecision OptionsIdeal Use Case
GGUFllama.cpp / OllamaCPU, Apple Silicon, Nvidia/AMD GPUsK-quants (Q4_K_M, Q5_K_M, Q8_0)Local execution on mixed hardware, Mac Studio, desktop PCs
EXL2ExLlamaV2Nvidia GPUs (CUDA exclusive)Variable bitrates (3.0 to 8.0 bits/weight)Ultra-fast token generation on dedicated Nvidia GPUs
AWQvLLM / HuggingFaceNvidia GPUs (TensorRT-LLM, vLLM)4-bit (INT4)Multi-user server deployment, high-concurrency workloads
Unsloth / BitsAndBytesPyTorch / TransformersNvidia GPUs4-bit (NF4), 8-bit (INT8)Local fine-tuning (QLoRA) and quick prototyping

4. Deep Dive into GGUF: The King of Local Inference

Developed by Georgi Gerganov and the llama. cppcpp community, GGUF (GPT-Generated Unified Format) replaced the legacy GGML format. It stores model architecture metadata, vocabulary, and quantised tensor weights inside a single binary file.

Understanding GGUF K-Quants

GGUF quantisation divides tensor weights into blocks and stores them using lower-precision representations. Different quantisation schemes use different block sizes, scales, and precision strategies to balance model quality against file size and memory usage.

Which GGUF Variant Should You Download?

  • Q8_0 (8-bit): Virtually zero perplexity loss compared to FP16. Best used when you have excess VRAM and want maximum accuracy.

  • Usually provides a strong quality-to-size balance, with relatively small degradation compared with higher-precision versions on many models.

  • Q4_K_M is one of the most widely used choices for local deployment because it offers a strong balance between model size, memory usage, speed, and output quality.

  • Q2_K or Q3_K_S (2/3-bit): Aggressive compression. Perplexity degrades noticeably; generally not recommended unless trying to run massive models on severely constrained hardware.

5. VRAM Footprint & Hardware Sizing Matrix

To calculate the VRAM required to load a model in GGUF format, use this working estimation formula:

The 1.2 multiplier is only a rough estimate for quantisation metadata and runtime overhead. KV-cache memory should be estimated separately because it can grow substantially with context length. 

(Note: The $1.2$ multiplier accounts for PyTorch overhead, CUDA context, and activation memory.)

Realistic Hardware Sizing (7B to 70B Models)

Model SizePrecision / QuantModel Weight SizeRecommended VRAMSuitable Hardware
7B / 8BFP16 (Unquantized)~15 GB20 GB+RTX 3090 / 4090, A6000
7B / 8BQ5_K_M (5-bit)~5.5 GB8 GBRTX 3060 / 4060, Apple M1/M2/M3 (8GB+)
7B / 8BQ4_K_M (4-bit)~4.8 GB6 GBGTX 1660 Ti, Mobile GPUs
14B / 16BQ4_K_M (4-bit)~9.5 GB12 GBRTX 3060 (12GB), RTX 4070
32B / 35BQ4_K_M (4-bit)~20 GB24 GBRTX 3090 / 4090, Single 24GB VRAM GPU
70BQ4_K_M (4-bit)~42 GB48 GB+Dual RTX 3090/4090, Apple Mac Studio (64GB+)

6. Hands-On Execution: Quantising & Serving Locally

Option A: Running Pre-Quantized Models with Ollama

Ollama automates model fetching, CPU/GPU offloading, and GGUF execution under the hood:

# 1. Pull and run a 4-bit quantised Qwen2.5 7B model

ollama run qwen2.5:7b-instruct-q4_K_M

# 2. Check active VRAM usage and model offload status
ollama ps

# Expected Terminal Output:

NAME                     ID           SIZE     PROCESSOR    UNTIL
qwen2.5:7b-instruct-q4   a1b2c3d4e5f6  4.7 GB   100% GPU     4 minutes from now
# Check active VRAM usage and model offload status ollama ps

Option B: Converting HuggingFace Weights to GGUF using llama.cpp

If you fine-tuned a custom model and need to build a GGUF binary manually:

# 1. Clone the llama.cpp repository
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp

# 2. Install Python dependencies
pip install -r requirements.txt

# 3. Convert FP16 HuggingFace model to GGUF FP16 format
python3 convert_hf_to_gguf.py /path/to/my-custom-model --outfile custom-fp16.gguf

# 4. Quantise the FP16 GGUF down to Q4_K_M precision
./llama-quantize custom-fp16.gguf custom-Q4_K_M.gguf Q4_K_M

# 5. Build & Run model directly in Terminal (Interactive Chat)
cmake -B build && cmake --build build --config Release
./build/bin/llama-cli -m custom-Q4_K_M.gguf -cnv -p "You are a helpful assistant."


7. Performance & Quality Evaluation: What Do You Lose?

Quantisation does not affect all aspects of a model equally:

  1. Perplexity (PPL): Lower bit-widths increase perplexity (a measure of statistical uncertainty). Moving from FP16 to Q5_K_M typically causes an imperceptible rise in PPL ($< 0.05$). Dropping below 3 bits causes PPL to spike sharply.

  2. Reasoning & Code Generation: Mathematical tasks, code syntax, and complex multi-step reasoning are the first capabilities to suffer at low bitrates ($\le \text{3-bit}$).

  3. Roleplay & General Text Generation: Summarisation, creative writing, and conversational chat remain surprisingly resilient even at 4-bit quantisation.

Summary Strategy

  • For Coding & Complex Logic: Use Q5_K_M or Q6_K.

  • For General Chat & Retrieval (RAG): Use Q4_K_M.

  • For High-Throughput Production: Use AWQ or EXL2 on dedicated Nvidia hardware for maximum generation speed (tokens per second).

 

Share: 𝕏 in @
[Object]

Writer at Tech World Desk. Passionate about technology, gadgets and everything in between.

Comments